<!--
 * @Author: your name
 * @Date: 2021-12-22 16:33:26
 * @LastEditTime: 2021-12-23 00:26:02
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \briup_am\am-ui\src\pages\play\team\list.vue
-->
<template>
  <div>
    <el-row>
      <el-col :span="12">
        <el-form :model="params" inline size="small">
          <el-form-item>
            <el-input v-model="params.name"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="queryHandler">搜索</el-button>
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :span="12" style="text-align:right">
        <el-button type="primary" size="small" @click="toAddHandler">录入</el-button>
      </el-col>
    </el-row>
   
    <el-table size="small" :data="teamData.list">
      <el-table-column label="球队编号" prop="id" width="100" align="center"></el-table-column>
        <el-table-column type="expand">
        <template slot-scope="slot">
          <ul style="display:flex">
            <li style="height:200px; overflow:hidden" v-for="p in slot.row.end_photos" :key="p">
              <img style="width:100%" :src="p" alt="">
            </li>
          </ul>
        </template>
      </el-table-column>
      <el-table-column label="球队名称" prop="team_name" width="200" align="center"></el-table-column>
       <el-table-column label="球队状态" prop="team_state" width="100" align="center"></el-table-column>
        <el-table-column label="接收状态" prop="receive_state" width="100" align="center"></el-table-column>
      <el-table-column label="创建时间" prop="creat_time" align="center"></el-table-column>
      <el-table-column label="球队实力" prop="team_strength" width="100" align="center"></el-table-column>
      <el-table-column label="出场费" prop="appearance_fee" width="100" align="center"></el-table-column>
      <el-table-column label="教练" prop="coach" width="100" align="center"></el-table-column>
      <el-table-column label="队长" prop="captain" width="100" align="center">
            <el-table-column label="队员详情" width="100" align="center">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="toPlayHandler(scope.row)">详情</el-button>
        </template>
      </el-table-column>
       <el-table-column label="接收状态" prop="online_status" width="100" align="center"></el-table-column>
        <template slot-scope="scope">
          <el-tag size="mini" type="success" v-if="scope.row.online_status == 1">备赛</el-tag>
          <el-tag size="mini" type="danger" v-else>休整</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="接受状态" prop="bind_status" width="100" align="center">
        <template slot-scope="scope">
          <el-tag size="mini" type="success" v-if="scope.row.bind_status == 1">已接受</el-tag>
          <el-tag size="mini" type="danger" v-else>已拒绝</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="100" align="center">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="toEditHandler(scope.row)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      layout="prev, pager, next"
      hide-on-single-page
      :total="+teamData.total"
      :current-page="+teamData.page"
      :page-size="+teamData.pageSize"
      @current-change="pageChangeHandler"
    ></el-pagination>

    <el-dialog :title="title" :visible.sync="visible">
    
      <el-form :model="form" label-width="80px">
        <el-form-item label="球队编号" >
          <el-input v-model="form.id" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="球队名称" >
          <el-input v-model="form.team_name" autocomplete="off"></el-input>
        </el-form-item>
         <el-form-item label="出场费" >
          <el-input v-model="form.appearance_fee" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="visible = false">取 消</el-button>
        <el-button size="small" type="primary" @click="submitHandler">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>,

<script>
import {get,postJSON} from '@/utils/request'
export default {
  data(){
    return {
      params:{
        page:1,
        pageSize:10
      },
      title:"",
      visible:false,
      form:{},
      teamData:{list:[]}
    }
  },
  mounted() {
    this.loadTeams();
  },
  methods:{
    queryHandler(){
      this.params.page = 1;
      this.loadTeams();
    },
    submitHandler(){
      let url ="/team/saveOrUpdate"
      postJSON(url,this.form).then(resp => {
        this.$message({type:"success",message:resp.message})
        this.visible = false;
        this.loadTeams();
      })
    },
    toEditHandler(row){
      this.form = row;
      this.title = "更改球队信息"
      this.visible = true;
    },
    toPlayHandler(row){
this.$router.push({
        path:'/play/player/list',
        query:row
      })
    },
    // 加载设备数据
    loadTeams(){
      let url = "/team/pageQuery";
      get(url,this.params).then(resp => {
        this.teamData = resp.data;
      })
    },
    pageChangeHandler(page){
      this.params.page = page;
      this.loadTeams();
    },
    toAddHandler(){
      this.visible = true;
      this.title = "录入球队";
      this.form = {}
    }
  }
}
</script>